 
 const {NAME_OR_PASSWORD,NAME_IS_EXISTS}=require("../constants/error_type")
  const userService=require("../service/UserService")
  const md5password=require("../utils/password_handle")
  //注册用户判断   判断用户是否存在
  const visitorfily=async (ctx,next)=>{
     //获取传递值
     const {name,password}=ctx.request.body
     
    
     //判断
     if(!name||!password||name==""||password==""){
      
         const error=new Error(NAME_OR_PASSWORD)
         //发送错事件
         return ctx.app.emit("error",error,ctx)
     }
     //传入传递参数名字
   const result= await  userService.getName(name);
   if(result.length){
    const error=new Error(NAME_IS_EXISTS)
    return ctx.app.emit("error",error,ctx);
   }
    
    await next()
}
//进行密码加密
const passwordHandle=async (ctx,next)=>{

     let {password}=ctx.request.body;
 
     ctx.request.body.password=md5password(password)
   
     await next() 
}
module.exports={visitorfily,passwordHandle}